package org.limited.memory.generate;

import cn.hutool.core.io.file.FileAppender;
import cn.hutool.core.util.RandomUtil;
import lombok.extern.slf4j.Slf4j;
import org.limited.memory.utils.Constant;

import java.io.File;
import java.util.stream.IntStream;

@Slf4j
public class GenerateBigFile {
    public static void main(String[] args) {

        File file = new File(Constant.bigFilePath);
        IntStream.rangeClosed(1, 32).parallel().forEach(i -> {
            FileAppender appender = new FileAppender(file, 1024, true);
            while (file.length() < Constant.one_GB) {
                String content = RandomUtil.randomNumbers(11);
                log.info("FileAppender i:{},content:{}",i,content);
                appender.append(content);
            }
            appender.flush();
        });

        log.info(String.valueOf(file.length()));
    }
}

